/****************************************************************
 * I am the AC 130 vs Pirate game. I allow the user to control an 
 * AC130 gunship in the hunt for Modern day pirates. The player  
 * will be allowed to roam free across a section of ocean/coastline.  
 * In the water there will be four types of vessels: Merchant  
 * ships that the player must protect, Pirate ships that the player  
 * must identify and destroy, Fishing boats that look like Pirate  
 * ships that the player must not destroy, and Friendly Navy ships  
 * that can capture pirates for extra points. Time permitting there  
 * may also be ground targets to attack. 
 *
 * Key elements of this project will be the Player/AC130, the Ships,  
 * the ShipAI system, the collision grid, the debris controller, the  
 * Ground/Water, Clouds, and scoring system. This project will make  
 * use of an external text file to store useful game parameters,  
 * thus allowing us to play balance the game without recompiling  
 * the executable. 
 *****************************************************************
 * I am the Base screen class. I provide a default template for a 
 * screen of the game. I have functions that recieve data from the 
 * ScreenCtrl class. I also have a pointer to the game data class
 * this will allow me to share data with other screens, as well as 
 * access game data information.
 *****************************************************************/

#include "scIntro.h"
#include <math.h>

/// I am the constructor. I create all objcets native to this screen
scIntro::scIntro(){
	myScreenType = stIntro;
	timer = -255;
}
scIntro::~scIntro(){

}

// I am the initilization function. I accept the external GameData
// class and do the one time processing that requires a GameData 
// Pointer like load images from hash table paths. I am also
// responsible for passing the GameData pointer to this screen's
// internal components
void scIntro::Init(GameData *exGd){
	gd = exGd;
}

/// I am the screen start function. I run the processes that need to
/// be run after this screen gets control from another screen.
void scIntro::OnStart(){
	timer = -255;
}

/// I am the screen close function. I run the processes that need to
/// be run before this screen passes control from another screen.
void scIntro::OnClose(){}

/// I am the mouse down event handeler. I get the mouse's position in
/// the screen as well as the button index that was pressed. 
void scIntro::OnMouseDn(int mouseX, int mouseY, int bt){}

/// I am the mouse up event handeler. I get the mouse's position in
/// the screen as well as the button index that was pressed. 
/// go to main menu
void scIntro::OnMouseUp(int mouseX, int mouseY, int bt){
	gd->nxtScreen = stMainMenu;
}

/// I am the key down event handeler. I pass the allegro key code of 
/// the key that was pressed in the latest update cycle.
void scIntro::OnKeyDn(int keyCode){}

/// I am the key up event handeler. I pass the allegro key code of 
/// the key that was released in the latest update cycle.
/// go to main menu
void scIntro::OnKeyUp(int keyCode){
	gd->nxtScreen = stMainMenu;

}

/// I am the update function. I get the screen coordinates of the mouse
/// on a regular basis. All positional/animation updates should get 
/// processed here 
void scIntro::Update(){
	int step = gd->GetNum("introStep");
	if(step == 0) step =10;
	timer += step;
		// time out to next screen
	if( timer >= 256)gd->nxtScreen = stMainMenu;
}

/// I am the draw function. I get the back buffer passed in as 
/// an argument. I draw this screen's data to the back buffer once
/// per update cycle
void scIntro::Draw(BITMAP * myScreen){
	int val = timer;
	if(val < 0) val *= -1;
	val = 255 - val;
	clear_to_color(myScreen, makecol(
		gd->GetNum("introR")*val/255,
		gd->GetNum("introG")*val/255,
		gd->GetNum("introB")*val/255));
		// todo add logo
	sprintf(gd->debugTxt, "Put an alpha mask here for the logo");


}
